package com.haoshuang.zhouzhoubang.ui.page.welfare.tool

import com.haoshuang.zhouzhoubang.model.api.ApiRepo
import com.haoshuang.zhouzhoubang.model.bean.ShopWelfareRecordBean
import com.haoshuang.zhouzhoubang.model.bean.ToolUseRecordBean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.net.netRequest
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData

class ToolUseRecordViewModel : BaseViewModel() {

    /**
     * 使用记录
     */
    val getTeamToolLogData = StatefulMutableLiveData<MutableList<ToolUseRecordBean>>()
    fun getTeamToolLog(type: Int, page: Int) = netRequest {
        start { getTeamToolLogData.value = StateData.Loading }
        request { ApiRepo.getTeamToolLog(type, page) }
        success { getTeamToolLogData.value = StateData.Success(it.data) }
        error { code, msg ->
            getTeamToolLogData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 商城使用记录
     */
    val getGoodsWelfareLogData = StatefulMutableLiveData<MutableList<ShopWelfareRecordBean>>()
    fun getGoodsWelfareLog(welfare_id: Int?, page: Int) = netRequest {
        start { getGoodsWelfareLogData.value = StateData.Loading }
        request { ApiRepo.getGoodsWelfareLog(welfare_id, page) }
        success { getGoodsWelfareLogData.value = StateData.Success(it.data) }
        error { code, msg ->
            getGoodsWelfareLogData.value = StateData.Error(code, msg)
        }
    }

}